<template>
  <div>
    <router-link class="header-abs" tag="div" to="/" v-show="showAbs">
        <div class="iconfont head-back">&#xe624;</div>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="showOpacity">
      <router-link  to="/" >
        <div class="iconfont head-fixed-back">&#xe624;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      showOpacity: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      // console.log('触发了')
      const top = document.documentElement.scrollTop
      if(top>60){
        let opacity = top/140
        opacity= opacity>1 ? 1 : opacity
        this.showOpacity = { opacity }
        this.showAbs = false
      }else{
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll',this.handleScroll)
  },
  deactivated () {
    this.showAbs = true
    window.removeEventListener('scroll',this.handleScroll)
  }
}
</script>

<style lang='stylus' scode>
  @import '~styles/varibles.styl'
  .header-abs
    position: absolute
    top: .1rem
    left: .1rem
    width: .8rem
    height: .8rem
    border-radius: .4rem
    text-align: center
    line-height: .86rem
    background: rgba(0, 0, 0, 0.8)
    .head-back
      position: absolute
      top: 0
      left: .06rem
      width: .64rem
      text-align: center
      color: #fff
      font-size: .4rem
  .header-fixed
    position: fixed
    overflow: hidden
    z-index: 1
    top: 0
    left: 0
    right: 0
    height: $headerHtight
    line-height: $headerHtight
    color: #fff
    text-align: center
    font-size: .32rem
    background-color: #00bcd4
    .head-fixed-back
      position: absolute
      top: 0
      left: 0
      width: .64rem
      text-align: center
      color: #fff
      font-size: .4rem
</style>
